package DataStr.ex01;

public class ex03 {
    public static void main(String[] args) {
        int []L={1,2,-1,-2,3,-3,4};
        int left = 0; // 指向当前非负数
        int right = L.length - 1; // 指向当前负数
        while(left<right){
            while(left<right&&L[left]<0){//查阅负数
                left++;//从左边开始查，查到负数时，一直保持循环
            }
            while(left<right&&L[right]>=0){
                right--;//这个指针是从右边往左边
            }
            if(left<right){
                int temp=L[left];
                L[left]=L[right];
                L[right]=temp;
            }
        }
        System.out.print("移动后L="+"[");
        for(int i=0;i<L.length;i++){
            System.out.print(L[i]);
            if(i<L.length-1){
                System.out.print(",");
            }
        }
        System.out.print("]");
    }
}

